package com.example.audiobooks.recent.fragment;

import android.content.SharedPreferences;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.fragment.app.FragmentManager;

import com.example.audiobooks.R;
import com.example.audiobooks.base.BaseFragment;
import com.example.audiobooks.home.bean.BooksBean;

public class RecentFragment extends BaseFragment {


    private View rootView;

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
/*
        BooksBean booksBean = new BooksBean();
        int recent_key = booksBean.getRecent_key();
       */
        SharedPreferences i = mContext.getSharedPreferences("data", 0);
        recent_key = i.getInt("recent_key", 0);
        Log.d("TAG", "initView: " + recent_key);

        //避免重复调用onCreateView()方法
        if (rootView == null && recent_key == 1) {
            rootView = inflater.inflate(R.layout.fragment_recent_new, container, false);
            // 在此处调用你初始化控件的方法
        }else {
            rootView = inflater.inflate(R.layout.fragment_recent, container, false);
        }
        // 缓存的mView需要判断是否已经被加过parent，如果有parent需要从parent删除，要不然会发生这个rootView已经有parent的错误。
        ViewGroup parent = (ViewGroup) rootView.getParent();
        if (parent != null) {
            parent.removeView(rootView);
        }
        return rootView;
    }


    private int recent_key;

    @Override
    public View initView() {



        return rootView;
    }

    @Override
    public void initData() {
        Log.d("TAG", "initView: " + recent_key);
        super.initData();

    }
}
